package com.example.moblie202160614cwj0507;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class supplierActivity extends AppCompatActivity {

    private RadioGroup radGupSupplierName;
    private RadioButton radbtnSupplier1;
    private RadioButton radbtnSupplier2;
    private RadioButton radbtnSupplier3;
    private RadioButton radbtnSupplier4;
    private Button btnSupplierSubmit;
    private TextView tvSupplierTitle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_supplier);
        initView();
        btnSupplierSubmit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              int radBtbId=radGupSupplierName.getCheckedRadioButtonId();
              if (radBtbId!=-1){
                  RadioButton radioButton= findViewById(radBtbId);
                  String supplierName=radioButton.getText().toString();
                  Intent intent=new Intent();
                  intent.putExtra("supplier",supplierName);
                  setResult(RESULT_OK,intent);
                  finish();



              }

            }
        });
    }

    private void initView() {
        radGupSupplierName = (RadioGroup) findViewById(R.id.radGupSupplierName);
        radbtnSupplier1 = (RadioButton) findViewById(R.id.radbtnSupplier1);
        radbtnSupplier2 = (RadioButton) findViewById(R.id.radbtnSupplier2);
        radbtnSupplier3 = (RadioButton) findViewById(R.id.radbtnSupplier3);
        radbtnSupplier4 = (RadioButton) findViewById(R.id.radbtnSupplier4);
        btnSupplierSubmit = (Button) findViewById(R.id.btnSupplierSubmit);
        tvSupplierTitle = (TextView) findViewById(R.id.tv_supplier_title);
    }
}